<?php declare(strict_types=1);

/**
 * @package PluginMaker (Light Portal)
 * @link https://custom.simplemachines.org/index.php?mod=4244
 * @author Bugo <bugo@dragomano.ru>
 * @copyright 2021-2025 Bugo
 * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later
 *
 * @category plugin
 * @version 30.10.25
 */

namespace LightPortal\Plugins\PluginMaker;

use Bugo\Compat\Utils;
use LightPortal\Events\EventDispatcherInterface;
use LightPortal\Plugins\Event;
use LightPortal\Plugins\Plugin;
use LightPortal\Plugins\PluginAttribute;
use LightPortal\Utils\Icon;

use function LightPortal\app;

if (! defined('LP_NAME'))
	die('No direct access...');

#[PluginAttribute]
class PluginMaker extends Plugin
{
	public function init(): void
	{
		Utils::$context['lp_plugin_option_types'] = array_combine(
			[
				'text', 'url', 'color', 'int', 'float', 'check',
				'multiselect', 'select', 'range', 'title', 'desc', 'callback'
			],
			$this->txt['option_type_set']
		);
	}

	public function extendAdminAreas(Event $e): void
	{
		$areas = &$e->args->areas;

		$areas['lp_plugins']['subsections'] = array_merge(
			['main' => $areas['lp_plugins']['subsections']['main']],
			['add'  => [Icon::get('plus') . $this->txt['add']]],
			$areas['lp_plugins']['subsections']
		);
	}

	public function extendPluginAreas(Event $e): void
	{
		app()->add(Handler::class)->addArgument(EventDispatcherInterface::class);

		$e->args->areas['add'] = [app(Handler::class), 'add'];
	}

	public function credits(Event $e): void
	{
		$e->args->links[] = [
			'title' => 'Nette PHP Generator',
			'link' => 'https://github.com/nette/php-generator',
			'author' => 'David Grudl',
			'license' => [
				'name' => 'the New BSD License',
				'link' => 'https://github.com/nette/php-generator/blob/master/license.md'
			]
		];
	}
}
